package gist

import java.lang.reflect.Modifier
import scala.util.Random

case class A(val a: String)
case class B( final val b: String)
case class C(var c: String)

object IsFinalApp extends App {

  val m = Map("" -> "")
  m.apply("")

  println(20000 * (0.4 - 0.08))
  println(20000 * (0.4 - 0.08) * 6.17 * 0.25)

  println(20000 * (1.5 - 0.08) * 6.17)
  println(20000 * (1.5 - 0.08) * 6.17 * 0.25)

  def isFinalFun(clazz: Class[_], filedName: String) = {
    val f = clazz.getDeclaredFields().find(_.getName() == filedName).get
    val mods = f.getModifiers()
    Modifier.isFinal(mods)
  }

  println(isFinalFun(classOf[A], "a"))
  println(isFinalFun(classOf[B], "b"))
  println(isFinalFun(classOf[C], "c"))

  type TopicModel = Int

  def ranExtra(likeTopics: Set[TopicModel], appTopics: Set[TopicModel]) = {
    val diffTopics = appTopics -- likeTopics
    val likeCount = likeTopics.size
    val addQty = 30 + (if (likeCount < 6) 6 - likeCount else 0)
  }

  def random32(likeTopics: Set[TopicModel], appTopics: Set[TopicModel]) = {

    import Random._
    val diffTopics = appTopics -- likeTopics
    val likeCount = likeTopics.size
    val addQty = 30 + (if (likeCount < 6) 6 - likeCount else 0)
    val suffTopics = shuffle(diffTopics).grouped(addQty).toArray
    val resultTopics = suffTopics(nextInt(suffTopics.filter(_.size == addQty).length))
    shuffle(resultTopics ++ likeTopics)
  }

  val likeTopics = Set(1, 2, 3, 4, 5, 6)
  val appTopics = (0 to 1000).toSet

  println(random32(likeTopics, appTopics))

  println(List((1, true), (2, false), (3, true)).partition(_._2 == true))

}